#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>
using namespace std;

class Solution
{
public:
    int removeDuplicates(vector<int>& nums)
    {
        auto left = nums.begin();
        auto right = left + 1;
        while (right != nums.end() && left != nums.end())
        {
            while (right != nums.end() && *left == *right)
            {
                ++right;
            }
            if (right - left > 1)
            {
                left = nums.erase(left + 1, right);
                right = left + 1;
            }
            else
            {
                ++left;
                ++right;
            }
        }
        return nums.size();
    }
};

int main()
{
    vector<int> nums;
    nums.push_back(0);
    //nums.push_back(0);
    //nums.push_back(0);
    //nums.push_back(1);
    //nums.push_back(1);
    nums.push_back(1);
    //nums.push_back(2);
    nums.push_back(2);
    //nums.push_back(3);
    //nums.push_back(3);
    nums.push_back(4);
    for (auto e : nums)
    {
        cout << e << " ";
    }
    cout << endl;

    Solution s;
    cout << s.removeDuplicates(nums) << endl;
    for (auto e : nums)
    {
        cout << e << " ";
    }
    cout << endl;
}




class Solution
{
public:
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param numbers int整型vector
     * @return int整型
     */
    int MoreThanHalfNum_Solution(vector<int>& numbers)
    {
        // write code here
        sort(numbers.begin(), numbers.end());
        int k = 0;
        auto iter = numbers.begin();
        while (iter != numbers.end())
        {
            auto next = iter + 1;
            while (*iter == *next)
            {
                ++k;
                ++next;
            }
            if (k < numbers.size() / 2)
            {
                k = 0;
                iter = next;
            }
            else
            {
                break;
            }
        }

        return *iter;
    }
};